package com.atguigu.yygh.gateway.config;
/**
 * 统一跨域处理
 */

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.util.pattern.PathPatternParser;

@Configuration
public class CorsConfig {



    @Bean
    public CorsWebFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();

        config.addAllowedMethod("*");//设置允许请求方式
        config.addAllowedOrigin("*");//设置哪些客户端可以访问网关
        config.addAllowedHeader("*");//设置哪些请求头可以请求

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
        source.registerCorsConfiguration("/**", config);
       

        return new CorsWebFilter(source);
    }
}